const { Sequelize } = require("sequelize");
const sequelize = require("@/db/seq");

const AlbumCategory = sequelize.define("album_category", {
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  name: {
    type: Sequelize.STRING,
    allowNull: false,
    unique: true,
    comment: "分类名称",
  },
  description: {
    type: Sequelize.STRING,
    allowNull: true,
    comment: "分类描述",
  },
  createdAt: {
    type: Sequelize.DATE,
    allowNull: false,
    defaultValue: Sequelize.NOW,
    comment: "创建时间",
  },
  updatedAt: {
    type: Sequelize.DATE,
    allowNull: false,
    defaultValue: Sequelize.NOW,
    comment: "更新时间",
  },
}, {
  freezeTableName: true,
});
// 同步模型到数据库
// AlbumCategory.sync({ force: false, alter: true })

AlbumCategory.associate = (models) => {
  console.log(Object.keys(models))
  AlbumCategory.hasMany(models.blog_album, {
    foreignKey: 'categoryId',
    as: 'albums'
  });
};
module.exports = AlbumCategory;